(function () {
    'use strict';

    angular.module('KingAdmin.pages.pdev.devgroup')
        .controller('DevgroupCtrl', DevgroupCtrl);

    /** @ngInject */
    function DevgroupCtrl($scope, $stateParams, $uibModal, $state,$uibModalInstance, DevgroupService,DictService) {
        var kt = this;
        kt.devgroup = {};
        if ($stateParams.isAdd) {
            kt.isAdd = true;
        } else {
            kt.isAdd = false;
        }

        $scope.title = '设备分组';
        $scope.nodes = DevgroupService.getTreeData().result;

        kt.types = [];
        if (!kt.isAdd&&$stateParams.id) {
            DevgroupService.getInfo({id: $stateParams.id},
                function (data) {
                    kt.isItemShow = true;
                    kt.devgroup = data;
                })
        } else {
            kt.isItemShow = true;
            kt.devgroup.parentId = $stateParams.id;
        }

        kt.save = function () {
            DevgroupService.save(kt.devgroup,function (data) {
                $uibModalInstance.close(true);
            });
        }
    }
})();
